package com.fitness.front.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fitness.front.convertor.CourseConvertor;
import com.fitness.front.mapper.CourseMapper;
import com.fitness.front.modal.course.dto.CourseDto;
import com.fitness.front.modal.course.entity.Course;
import com.fitness.front.modal.course.params.CoursePageQueryParams;
import com.fitness.front.modal.course.vo.CourseVO;
import com.fitness.front.service.ICourseService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements ICourseService {

    private final CourseConvertor courseConvertor;

    @Override
    public Page<CourseVO> getCoursePage(CoursePageQueryParams queryParams) {
        // 参数构建
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();
        Page<Course> page = new Page<>(pageNum, pageSize);

        // 查询数据
        Page<Course> coachBoPage = this.baseMapper.getCoursePage(page, queryParams);

        return courseConvertor.entity2Vo(coachBoPage);
    }

    @Override
    public boolean addCourse(CourseDto courseDto) {
        return save(courseConvertor.dto2Entity(courseDto));
    }

    @Override
    public boolean updateCourse(CourseDto courseDto) {
        return updateById(courseConvertor.dto2Entity(courseDto));
    }

}
